package com.rich.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.Servlet;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rich.domain.Category;
import com.rich.domain.Order;
import com.rich.domain.Product;
import com.rich.service.CategoryService;
import com.rich.service.OrderService;
import com.rich.service.ProductService;

@Controller
@Scope("prototype")
public class IndexAction extends ActionSupport{

	@Resource
	private CategoryService categoryServiceimpl;
	@Resource
	private ProductService productServiceimpl;
	/**
	 * 首页分类条
	 */
	private static final long serialVersionUID = 1L;
	
	
	public String execute() {
		try {
			//查找一级分类
			List<Category> clist = categoryServiceimpl.findAll();
			//此处别用ServletActionContext
			ActionContext.getContext().getSession().put("cList", clist);
			//热门商品
			List<Product> hList = productServiceimpl.findByHot();
			//热门商品放入值栈中
			ActionContext.getContext().getValueStack().set("hList", hList);;
			//最新商品
			List<Product> nList = productServiceimpl.findByNew();
			
			//最新商品放入值栈
			ActionContext.getContext().getValueStack().set("nList", nList);
			return "index";
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
